# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Simon Zeni <simon@bl4ckb0ne.ca>
pkgname=spirv-tools
_pkgname=SPIRV-Tools
pkgver=1.3.290.0
pkgrel=0
pkgdesc="API and commands for processing SPIR-V modules"
url="https://github.com/KhronosGroup/SPIRV-Tools"
arch="all"
license="Apache-2.0"
depends_dev="spirv-headers $pkgname=$pkgver-r$pkgrel"
makedepends="$depends_dev cmake samurai python3"
subpackages="$pkgname-dev $pkgname-dbg"
source="$pkgname-$pkgver.tar.gz::https://github.com/KhronosGroup/SPIRV-Tools/archive/refs/tags/vulkan-sdk-$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-vulkan-sdk-$pkgver"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		cmake_crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi

	# reduce size of debug syms, lto
	CXXFLAGS="$CXXFLAGS -g1 -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DBUILD_SHARED_LIBS=ON \
		-DSPIRV_WERROR=OFF \
		-DSPIRV-Headers_SOURCE_DIR=/usr \
		-DSPIRV_TOOLS_BUILD_STATIC=OFF \
		$cmake_crossopts
	cmake --build build
}

check() {
	# Not all test are enabled, because they rely on googletest source
	# folder. While it is easy to add, the (extra) tests then also need
	# effcee and re2 as well.
	ctest --test-dir build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
d4e8440c0843fb084dde4a576b95442783ab8204670b199798bd87f754d77f3c258bb69ab1d4dd7859c1d2c681ed8813309c76c6f70b5a7d8d21b6a48ef63b67  spirv-tools-1.3.290.0.tar.gz
"
